home *** CD-ROM | disk | FTP | other *** search
/ Apple Reference & Presen…tion Library 2 (Reseller) / Apple R&P Lib Reseller v2.0.iso / 4-Fonts & Software / Demo Software / AppMaker / Demo AppMaker™ / Demo AppMaker™.rsrc / TmpP_204_MainMenu.txt < prev    next >
Encoding:
Text File  |  1989-04-09  |  3.8 KB  |  218 lines

  1. # (decoded with TMPL 11972)
  2. { %filename% }
  3. { Created %date% %time% by AppMaker }
  4.  
  5. Unit %unitname%;
  6. Interface
  7.  
  8. Uses
  9. %If MPW%
  10.     {$Load ToolBox.dump}
  11.         MemTypes,
  12.         QuickDraw,
  13.         OSIntf,
  14.         ToolIntf,
  15.         PackIntf,
  16.     {$Load}
  17.  
  18. %end if%
  19. %If Think%
  20. {$ifc undefined Think_Pascal}
  21.     ListManager,
  22. {$endc}
  23. %end if%
  24.     %UsesFiles%
  25.     Globals,
  26.     ResourceDefs;
  27.     
  28. {----------}
  29. Procedure InitTitles;
  30. Procedure LoadMenus;
  31. Procedure DoMenu (menuChoice:    longint);
  32. Procedure UpdateMenus;
  33.  
  34. {----------}
  35. Implementation
  36.  
  37. %If MPW%
  38. {$D+}
  39. {$R+}
  40. {$OV+}
  41.  
  42. %end if%
  43. %If MPW%
  44. {$S %unitname%}
  45.  
  46. %end if%
  47. {----------}
  48. Procedure InitTitles;
  49. Begin
  50.     %InitTitles%
  51. End; {InitTitles}
  52.  
  53. {----------}
  54. Procedure LoadMenus;
  55. Begin
  56.     %GetMenus%
  57.  
  58.     %InsertMenus%
  59.  
  60.     DrawMenuBar;
  61. End; {LoadMenus}
  62.  
  63. {----------}
  64. Procedure DoAbout;
  65. var
  66.     itemNr:            integer;
  67. Begin
  68.     itemNr := Alert (AboutID, nil);
  69. End; {DoAbout}
  70.  
  71. {----------}
  72. Procedure DoApple (itemNr:    integer);
  73. var
  74.     name:            Str255;
  75.     refNum:            integer;
  76. Begin
  77.     case itemNr of
  78.         AppleAbout:
  79.                 DoAbout;
  80.         otherwise begin
  81.                 GetItem (AppleMenu, itemNr, name);
  82.                 refNum := OpenDeskAcc (name);
  83.             end;
  84.     end; {case}
  85. End; {DoApple}
  86.  
  87. {----------}
  88. Procedure DoMenu {(menuChoice:    longint)};
  89. var
  90.     menuID:            integer;
  91.     itemNr:            integer;
  92. Begin
  93.     menuID := HiWord (menuChoice);
  94.     itemNr := LoWord (menuChoice);
  95.     
  96.     case menuID of
  97.         0:
  98.                 {Do nothing};
  99.         %HandleMenus%
  100.     end; {case}
  101.  
  102.     HiliteMenu (0);
  103. End; {DoMenu}
  104.  
  105. {----------}
  106. Procedure UpdateMenus;
  107. var
  108.     frontPeek:        WindowPeek;
  109.     isFront:        boolean;    {is there a front window?}
  110.     isCur:            boolean;    {is there a current window?}
  111.     isDirty:        boolean;    {is it dirty?}
  112.     hasFile:        boolean;    {does it have a file?}
  113.     isSelected:        boolean;    {is anything selected?}
  114.     isDesk:            boolean;    {is the front window a desk acc?}
  115.     isText:            boolean;    {is there a current text field?}
  116.     isScrap:        boolean;    {is there any scrap?}
  117.     menu:            MenuHandle;
  118.     menuBarChanged:    boolean;
  119.     
  120.     {----------}
  121.     Procedure Enable (itemNr:    integer;
  122.                       enabled:    boolean);
  123.     Begin
  124.         if enabled then begin
  125.             EnableItem  (menu, itemNr);
  126.         end else begin
  127.             DisableItem (menu, itemNr);
  128.         end;
  129.     End; {Enable}
  130.     
  131.     {----------}
  132.     Procedure EnableTitle (menu:    MenuHandle;
  133.                              enabled:    boolean);
  134.     Begin
  135.         if enabled <> odd (menu^^.enableFlags) then begin
  136.             menuBarChanged := true;
  137.         end;
  138.         if enabled then begin
  139.             EnableItem  (menu, 0);
  140.         end else begin
  141.             DisableItem (menu, 0);
  142.         end;
  143.     End; {EnableTitle}
  144.     
  145. Begin {UpdateMenus}
  146.  
  147.     menuBarChanged := false;
  148.  
  149.     isFront        := (FrontWindow <> nil);
  150.     isCur        := (curWindow <> nil);
  151.     isDirty     := false;
  152.     hasFile     := false;
  153.     isSelected    := false;
  154.     if isCur then begin
  155.         isDirty        :=  cur^.dirty;
  156.         HasFile        := (cur^.fileNum <> 0);
  157.     end;
  158.  
  159.     isDesk := false;
  160.     if isFront then begin
  161.         frontPeek    := WindowPeek (FrontWindow);
  162.         isDesk        := (frontPeek^.windowKind < 0);
  163.     end;
  164.     isText        := false;
  165.     if isCur then begin
  166.         isText        := (cur^.text <> nil);
  167.     end;
  168.     isScrap        := false;
  169.     if isText then begin
  170.         isSelected    := (cur^.text^^.selStart <> cur^.text^^.selEnd);
  171.         isScrap        := (TEGetScrapLen > 0);
  172.     end;
  173.     
  174.     menu := FileMenu;
  175. %if defined FileClose%
  176.     Enable (FileClose,        isFront);
  177. %end if%
  178. %if defined FileSave%
  179.     Enable (FileSave,        isDirty);
  180. %end if%
  181. %if defined FileSaveAs%
  182.     Enable (FileSaveAs,        isDirty);
  183. %end if%
  184. %if defined FileRevert%
  185.     Enable (FileRevert,        isDirty and hasFile);
  186. %end if%
  187.     
  188.     menu := EditMenu;
  189.     if isFront then begin
  190. %if defined EditUndo%
  191.         Enable (EditUndo,        isDesk);
  192. %end if%
  193. %if defined EditCut%
  194.         Enable (EditCut,        isDesk or isSelected);
  195. %end if%
  196. %if defined EditCopy%
  197.         Enable (EditCopy,        isDesk or isSelected);
  198. %end if%
  199. %if defined EditPaste%
  200.         Enable (EditPaste,        isDesk or isScrap);
  201. %end if%
  202. %if defined EditClear%
  203.         Enable (EditClear,        isDesk or isSelected);
  204. %end if%
  205. %if defined EditSelectAll%
  206.         Enable (EditSelectAll,    isText);
  207. %end if%
  208.     end;
  209.  
  210.     EnableTitle (EditMenu,     isFront);
  211.  
  212.     if menuBarChanged then begin
  213.         DrawMenuBar;
  214.     end;
  215. End; {UpdateMenus}
  216.  
  217. End. {%unitname%}
  218.